<template>
<div style="height:100%">

 
<div style="font-size: 16px;font-weight: bold;margin-left: 16px;margin-top:20px;height: 37px;">参保人员信息</div>
<!--       
      <el-popover
      v-model='popvisiable'
  placement="right"
  width="400"
  trigger="click"> -->
   <el-dialog
      title="新增人员"
      :visible.sync="popvisiable"
      width="395px"
      >
  <div>
    <el-form>
  <el-form-item label="姓名" style="width: 50%;" label-width="100px" required>
      <el-input v-model="additem.username" placeholder="请输入内容" style="width: 220px"></el-input>
  </el-form-item>
  <el-form-item label="身份证号" style="width: 50%;" label-width="100px" required>
      <el-input v-model="additem.creditcard" placeholder="请输入内容" style="width: 220px"></el-input>
  </el-form-item>
  <el-form-item    label="手机号" style="width: 50%;" label-width="100px" :required="additem.relation!=3">
      <el-input v-model="additem.phone" placeholder="请输入内容" style="width: 220px"></el-input>
  </el-form-item>
  <!-- <el-form-item label="年龄" style="width: 50%;" label-width="120px" required>
    <el-input v-model="additem.age" placeholder="请输入内容" style="width: 220px"></el-input>
</el-form-item> -->
  <el-form-item label="与员工关系" style="width: 50%;" label-width="100px">
      <el-select  @change="$forceUpdate()"  v-model="additem.relation" placeholder="请选择" style="width: 220px;">
                <el-option  label='本人' :value="1">本人</el-option>
                <!-- <el-option  label='配偶'  value="1">配偶</el-option>
                <el-option   label='子女' value="2">子女</el-option> -->
      </el-select>
    </el-form-item>
    </el-form>
  </div>
      <span slot="footer" class="dialog-footer">
                <el-button @click="popvisiable = false">取 消</el-button>

        <el-button  @click="addmember"  slot="reference" type="primary" style="margin: 20px;">保存</el-button>
        <!-- position: relative;float: right; -->
  </span>
   </el-dialog>
    <!-- </el-popover> -->

    <el-button @click="popvisiable=true;" slot="reference" type="primary" style="position: relative;float: right;margin: 20px;">新增人员</el-button>

    <el-upload  :on-change="importf"  action="" :auto-upload="false"	 style="position: relative;float: right;margin: 20px;">
<el-button   type="primary" >批量导入新增人员</el-button>
    </el-upload>
<i @click="download" class="el-icon-download" style="cursor:pointer;position: relative;float: right;line-height:40px;margin:20px">下载人员名单模板</i>

      <!-- <el-button type="success" style="position: relative;float: right;margin: 20px;">导入人员</el-button> -->
  <!-- default-expand-all   v-if="tabletag"    default-expand-all      <!-- border -->
 
      <el-table
        
      :data="member"
      style="width: 100%;margin-bottom: 20px;"
      row-key="ids"
       ref="treeTable"
    default-expand-all 
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <!-- <el-table-column
      type="selection"
      width="55">
    </el-table-column> -->
    <el-table-column
   
      prop="username"
      label="被保险人姓名">
    </el-table-column>
    <el-table-column
      prop="creditcard"
       label="身份证号">
    
    </el-table-column>
    <el-table-column
      prop="phone"
      label="手机号">
    </el-table-column>
    <el-table-column
     prop="age"
    label="年龄"
    width="60">
  </el-table-column>
  <el-table-column
  prop="comment"
   label="月保费"
  width="100">
</el-table-column>
    <el-table-column
     label="与被保险人关系">
    <template slot-scope="scope">
      {{scope.row.relation==1?'本人':(scope.row.relation==2?'配偶':'子女')}}
      </template>
  </el-table-column>
    <el-table-column
     fixed="right"
    label="操作"
    width="260">
    <template slot-scope="scope">
      <el-button v-if="scope.row.updatetag==0||!scope.row.updatetag"    @click="delmember(scope.$index,member)" type="text" size="small">删除</el-button>
      <el-button v-if="scope.row.updatetag==1" @click="handleClick(scope.row,scope)" type="text" size="small">减员</el-button>
      <el-button v-if="scope.row.updatetag==2" @click="handleClick2(scope.row,scope)" type="text" size="small">开启</el-button>

      <el-button  @click=" readyedit(scope.row,scope.$index)" type="text" size="small">编辑</el-button>
      <el-button v-if="!scope.row.son"  @click="dialogVisible = true;currentindex=scope.$index" type="text" size="small">添加家庭成员</el-button>

    </template>
  </el-table-column>
  </el-table>
  <el-button @click="tijiao" type="primary" style="position: relative;float: right;margin: 20px;">保存</el-button>
      




      <el-dialog
      title="添加家庭成员"
      :visible.sync="dialogVisible"
      width="395px"
      :before-close="handleClose">
      <div>
        <el-form>
        <el-form-item label="姓名" style="width: 50%;" label-width="120px" required>
            <el-input v-model="addhome.username" placeholder="请输入内容" style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" style="width: 50%;" label-width="120px" required>
            <el-input v-model="addhome.creditcard" placeholder="请输入内容"  style="width: 220px"></el-input>
        </el-form-item>
        <el-form-item   label="手机号" style="width: 50%;" label-width="120px" :required="addhome.relation!=3">
            <el-input v-model="addhome.phone" placeholder="请输入内容" style="width: 220px"></el-input>
        </el-form-item>
        <!-- <el-form-item label="年龄" style="width: 50%;" label-width="120px" required>
          <el-input v-model="addhome.age" placeholder="请输入内容" style="width: 220px"></el-input>
      </el-form-item> -->
        <el-form-item label="与员工关系" style="width: 50%;" label-width="120px">
            <el-select  @change="$forceUpdate()"  v-model="addhome.relation" placeholder="请选择" style="width: 220px">
                <!-- <el-option  label='本人' value="0">本人</el-option> -->
                <el-option  label='配偶'  :value="2">配偶</el-option>
                <el-option   label='子女' :value="3">子女</el-option>
            </el-select>
          </el-form-item>
        </el-form>
         </div>
              <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
       

        <el-button type="primary" @click="addhomemember">确 定</el-button>
         
      </span>
    </el-dialog>


    <el-dialog
    title="编辑"
    :visible.sync="dialogeditVisible"
    width="30%"
    :before-close="handleeditClose">
    <div>
      <el-form>
      <el-form-item label="姓名" style="width: 50%;" label-width="120px" required>
          <!-- <el-input v-model="edititem.username" placeholder="请输入内容" style="width: 220px"></el-input> -->
     <input v-model="edititem.username" placeholder="请输入内容" style="width: 220px;line-height:40px" disabled></input>

      </el-form-item>
      <el-form-item label="身份证号" style="width: 50%;" label-width="120px" required>
          <!-- <el-input v-model="edititem.creditcard" placeholder="请输入内容" style="width: 220px"></el-input> -->
                    <input v-model="edititem.creditcard" placeholder="请输入内容" style="width: 220px;line-height:40px" disabled></input>

      </el-form-item>
      <el-form-item     label="手机号" style="width: 50%;" label-width="120px" :required="edititem.relation!=3">
          <!-- <el-input v-model="edititem.phone" placeholder="请输入内容" style="width: 220px"></el-input> -->
    <input v-model="edititem.phone" placeholder="请输入内容" style="width: 220px;line-height:40px"></input>

      </el-form-item>
      <!-- <el-form-item label="年龄" style="width: 50%;" label-width="120px" required>
        <el-input v-model="edititem.age" placeholder="请输入内容" style="width: 220px"></el-input>
    </el-form-item> -->
      <el-form-item v-show="edititem.son" label="与员工关系" style="width: 50%;" label-width="120px">
         <el-select @change="$forceUpdate()" v-model="edititem.relation" placeholder="请选择" style="width: 220px;">
                     <el-option  label="配偶" :value="2">配偶</el-option>
                    <el-option  label="子女" :value="3">子女</el-option>
          </el-select>  
  <!-- <select @change="$forceUpdate()"  style="width: 220px;" name="public-choice" v-model="edititem.relation"  >                                        
    <option   value="2"   >配偶</option>    
      <option   value="3"   >子女</option>                                   
</select> -->
        </el-form-item>
      </el-form>
        <!-- <el-button slot="reference" type="primary" style="position: relative;float: right;margin: 20px;">保存</el-button> -->
      </div>
      
    <span slot="footer" class="dialog-footer">
      <el-button   @click="dialogeditVisible = false">取 消</el-button>
      <el-button type="primary" @click="editmember">确 定</el-button>
    </span>
  </el-dialog>

  


  </div>
</template>

<script>
import { getmembersofpolicy,updatememberofpolicy,getpricelist } from '@/api/policy'
import XLSX from 'xlsx'
export default {
  name: 'addcustomerlead',
  components: { },
    computed: {
  },
   data() {
      return {
       
        itemids:[],
        prices:[],
        showsource:true,
        showsource2:true,
        paymenttype:1,
        datareadonly:false,
        datareadonly2:false,
        allmembers:[],
        allcustomers:[],
        allcustomersofuser:[],
        tabletag:true,
        currentindex:0,
        idindex:1,
        bzqx:1,
        popvisiable:false,
        member:[ ],
        additem:{relation:1},
        edititem:{ relation:1},
        addhome:{relation:2},
        dialogVisible: false,
        dialogeditVisible: false,
        tuancode:[],

        itemid3:'',
        itemid:'',
        beiname:'',
        guanxi:'',
        beicard:'',
        beiphone:'',
        tableData: [],
        begintimeori:'',
        imageUrl: '',
        lianxiname:'',
        card:'',
        nashuiren:'',
        hangye:'',
        guimo:'',
        lianxiphone:'',
        comname:'',
        comaddress:'',
        customerid:'-2',
        customerid2:'-2',
        customercontent:{customertype:2},
        customercontent2:{customertype:1},
        customertype:2,
        endtimeori:'',
        itemid2: "",
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: '',
          options: [
          {
          value: '1',
          label: '平安保险',
          children: [
                {
                   value: '361',
                   label: '黄金型',
                }, 
                {
                   value: '360',
                   label: '白金型',

                }, 
                {
                   value: '362',
                   label: '钻石型',

                }]
        },
        {
          value: '2',
          label: '泰安保险',
          children: [
                {
                   value: '359',
                   label: '活动组织责任险',
                }, 
                {
                   value: '358',
                   label: '活动意外险',

                }]
        }

      ]
        },
        
    }
  
      
  },
  components:{


  },
  activated(){
    // this.getpossiblemembers(0);

  },
  mounted(){
    this.itemids=JSON.parse(sessionStorage.getItem('itemids') );

  this.getmembers();
 this.getpricelist();
  },
  methods:{
  download(){
    location.href='http://chudan.zhiyuewulian.com/temp/moban.xlsx';
    
    },
          readyedit(dt,index){

       
        this.edititem={};
        // this.edititempointer=dt;
        this.edititem.username=dt.username; 
        this.edititem.creditcard=dt.creditcard; 
        this.edititem.phone=dt.phone; 
        this.edititem.son=dt.son; 
        this.edititem.relation=dt.relation; 
        this.edititem.age=dt.age; 
        this.edititem.comment=dt.comment;
             console.log(this.edititem)
         this.currentindex=index;
        this.dialogeditVisible = true;

      },
            importf(obj) {//导入
            console.log(obj)
        var rABS=false;
        var wb;
        // obj=obj.target;
            // layer.load(2);
            this.$loadingshow();
                if(!obj ) {
            this.$loadingclose();
                    return;
                }
                var f = obj.raw;
                 if(f.name.indexOf(".xlsx")!=(f.name.length-5))
                 {
                    this.$loadingclose();
                 this.$toast('选择的文件不是excel格式，请下载模板');
                 return;
                 }
                var reader = new FileReader();
                var that=this;
                reader.onload = function(e) {
                    var data = e.target.result;
                    if(rABS) {
                        wb = XLSX.read(btoa(fixdata(data)), {//手动转化
                            type: 'base64'
                        });
                    } else {
                        wb = XLSX.read(data, {
                            type: 'binary'
                        });
                    }
                    //wb.SheetNames[0]是获取Sheets中第一个Sheet的名字
                    //wb.Sheets[Sheet名]获取第一个Sheet的数据
                   var result=  XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]])  ;
                   var infoitem='<tr><td class="ui-table-checkbox"><input type="checkbox"></td><td></td><td><div class="ui-table-td">[name]</div></td><td>[cardtype]</td><td>[card]</td><td>[sex]</td><td>[age]</td><td>[phone]</td><td>[health]</td><td class="ui-table-checkbox"><input type="checkbox" checked disabled></td><td class="ui-table-checkbox"><input type="checkbox" [checked2]></td><td><a>编辑</a></td></tr>';
                   
                   var allarr=[];
                   var q=0;
                    for(var i=0;i<result.length;i++)
                    {
                     // if(cardarr.indexOf(result[i].证件号码)==-1)
                      //{
                      
                      var arritem={};
                      var children=[];
                     
                      arritem.username=result[i]['员工姓名'];
                      arritem.creditcard=result[i]['员工身份证号'];
                    
                      arritem.phone=result[i]['员工手机号'];
                       if(!arritem.username&&!arritem.creditcard&&!arritem.phone)
                      {
                        continue;
                      }
                      if(arritem.username)
                      {
                        arritem.username=arritem.username.replace(/\r\n/g,"")
                      arritem.username=arritem.username.replace(/\s/g,"")

                      }
                      else
                      arritem.username='';
                      if(arritem.creditcard)
                      {
                        arritem.creditcard=arritem.creditcard.replace(/\r\n/g,"")
                      arritem.creditcard=arritem.creditcard.replace(/\s/g,"")
                        
                      }
                      else
                      arritem.creditcard='';
                      if(arritem.phone)
                      {

                        arritem.phone=arritem.phone.replace(/\r\n/g,"")
                      arritem.phone=arritem.phone.replace(/\s/g,"")
                        
                      }
                      else
                      {
                    arritem.phone='';
                      }


                      arritem.son=false;
                      arritem.relation=1;
                     
                      arritem.ids=that.idindex;
                      that.idindex+=1;
                      arritem.age=that.GetAge(arritem.creditcard);
                         that.getprice(arritem)
                      if(result[i]['员工配偶姓名']||result[i]['员工配偶身份证号']||result[i]['员工配偶手机号'])
                      {
                         var child={};
                         child.username=result[i]['员工配偶姓名'];
                         child.creditcard=result[i]['员工配偶身份证号'];
                         child.phone=result[i]['员工配偶手机号'];
                         if(!child.phone)
                         child.phone='';
                         if(child.username)
                         {
                         child.username=child.username.replace(/\r\n/g,"")
                         child.username=child.username.replace(/\s/g,"")
                         }
                         if(child.creditcard)
                         {
                         child.creditcard=child.creditcard.replace(/\r\n/g,"")
                         child.creditcard=child.creditcard.replace(/\s/g,"")
                         }
                         if(child.phone)
                         {
                         child.phone=child.phone.replace(/\r\n/g,"")
                         child.phone=child.phone.replace(/\s/g,"")
                         }
                         child.relation=2;
                         child.son=true;
                         child.age=that.GetAge(child.creditcard);
                         that.getprice(child)
                         q=q+1;
                         child.ids=that.idindex;
                         that.idindex+=1;
                        // arritem.son=false;
                         children.push(child);
                       

                      }
                      
                      if(result[i]['员工子女姓名1']||result[i]['员工子女身份证号1'] )
                      {
                         var child={};
                         child.username=result[i]['员工子女姓名1'];
                         child.creditcard=result[i]['员工子女身份证号1'];
                         child.phone='';
                         if(child.username)
                         {
                         child.username=child.username.replace(/\r\n/g,"")
                         child.username=child.username.replace(/\s/g,"")
                         }
                         if(child.creditcard)
                         {
                         child.creditcard=child.creditcard.replace(/\r\n/g,"")
                         child.creditcard=child.creditcard.replace(/\s/g,"")
                         }
                       
                         child.relation=3;
                         child.son=true;
                         q=q+1;
                         child.ids=that.idindex;
                         that.idindex+=1;
                         child.age=that.GetAge(child.creditcard);
                         that.getprice(child)
                        // arritem.son=true;
                         children.push(child)

                      }
                       
                      if(result[i]['员工子女姓名2']||result[i]['员工子女身份证号2'] )
                      {
                         var child={};
                         child.username=result[i]['员工子女姓名2'];
                         child.creditcard=result[i]['员工子女身份证号2'];
                         child.phone='';
                         if(child.username)
                         {
                         child.username=child.username.replace(/\r\n/g,"")
                         child.username=child.username.replace(/\s/g,"")
                         }
                         if(child.creditcard)
                         {
                         child.creditcard=child.creditcard.replace(/\r\n/g,"")
                         child.creditcard=child.creditcard.replace(/\s/g,"")
                         }
                         child.relation=3;
                         child.son=true;
                         child.age=that.GetAge(child.creditcard);
                         that.getprice(child)
                         
                         child.ids=that.idindex;
                         that.idindex+=1;
                        // arritem.son=true;
                         children.push(child)

                      }

                       
                        arritem.children=children;
                      

                        
                   
                
                
					          
                       allarr.push(arritem);
         
                       
                      }
                      console.log(allarr)
                       that.member=that.member.concat(allarr);
                       console.log('导入成功'+allarr.length)
                            that.$loadingclose();
                      
                   // }
                    
                     
                };
                if(rABS) {
                    reader.readAsArrayBuffer(f);
                } else {
                    reader.readAsBinaryString(f);
                }
                
            },
            getprice(people){

              for(var i=0;i<this.prices.length;i++)
        {
            if(people.age<=this.prices[i].agemax&&people.age>=this.prices[i].agemin)
            people.comment=this.prices[i].price;

        }
        console.log(people.name+":"+people.comment)

            },
         GetAge(identityCard) {
    var len = (identityCard + "").length;
    if (len == 0) {
        return 0;
    } else {
        if ((len != 15) && (len != 18))//身份证号码只能为15位或18位其它不合法
        {
            return 0;
        }
    }
    var strBirthday = "";
    if (len == 18)//处理18位的身份证号码从号码中得到生日和性别代码
    {
        strBirthday = identityCard.substr(6, 4) + "/" + identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
    }
    if (len == 15) {
        strBirthday = "19" + identityCard.substr(6, 2) + "/" + identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
    }
    //时间字符串里，必须是“/”
    var birthDate = new Date(strBirthday);
    var nowDateTime = new Date();
    var age = nowDateTime.getFullYear() - birthDate.getFullYear();
    //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
    if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
        age--;
    }
    return age;
},
            IdentityCodeValid(code) { 
            var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
            var tip = "";
            var pass= true;

            if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
                tip = "身份证号格式错误";
                pass = false;
            }

           else if(!city[code.substr(0,2)]){
                tip = "地址编码错误";
                pass = false;
            }
            else{
                //18位身份证需要验证最后一位校验位
                if(code.length == 18){
                    code = code.split('');
                    //∑(ai×Wi)(mod 11)
                    //加权因子
                    var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
                    //校验位
                    var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
                    var sum = 0;
                    var ai = 0;
                    var wi = 0;
                    for (var i = 0; i < 17; i++)
                    {
                        ai = code[i];
                        wi = factor[i];
                        sum += ai * wi;
                    }
                    var last = parity[sum % 11];
                    if(parity[sum % 11] != code[17]){
                        tip = "校验位错误";
                        pass =false;
                    }
                }
            }
            if(!pass) 
           console.log(tip);
            return pass;
        },
         GetAge(identityCard) {
    var len = (identityCard + "").length;
    if (len == 0) {
        return 0;
    } else {
        if ((len != 15) && (len != 18))//身份证号码只能为15位或18位其它不合法
        {
            return 0;
        }
    }
    var strBirthday = "";
    if (len == 18)//处理18位的身份证号码从号码中得到生日和性别代码
    {
        strBirthday = identityCard.substr(6, 4) + "/" + identityCard.substr(10, 2) + "/" + identityCard.substr(12, 2);
    }
    if (len == 15) {
        strBirthday = "19" + identityCard.substr(6, 2) + "/" + identityCard.substr(8, 2) + "/" + identityCard.substr(10, 2);
    }
    //时间字符串里，必须是“/”
    var birthDate = new Date(strBirthday);
    var nowDateTime = new Date();
    var age = nowDateTime.getFullYear() - birthDate.getFullYear();
    //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
    if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
        age--;
    }
    return age;
},
 // 判断是否为手机号
  isPoneAvailable (pone) {
    var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
    if (!myreg.test(pone)) {
      return false;
    } else {
      return true;
    }
  },
     getmembers(){

this.$loadingshow();
       getmembersofpolicy({ policyid:this.$route.query.id }).then(res => {
      this.$loadingclose();
       if (res.code == 200) {
               this.member=res.result;
               this.member.forEach(element => {
                 element.oriupdatetag=element.updatetag;
                 element.ids=this.idindex;
                 this.idindex+=1;
               });
               
           //   document.getElementsByClassName('el-table__body-wrapper')[0].style.height='auto';
        } 
        else{
          this.$toast(res.message)
        }
      });
    },
        handleClose(done) {
        // this.$confirm('确认关闭？')
        //   .then(_ => {
        //     done();
        //   })
        //   .catch(_ => {});
        done();
      },
      handleeditClose(done) {
        // this.$confirm('确认关闭？')
        //   .then(_ => {
        //     done();
        //   })
        //   .catch(_ => {});
        done();
      },
      getNowFormatDate(dt) {
        var date = new Date(dt);
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    },
    lockmember(id,index)
    {
        
     this.$loadingshow();
       lockmember({ id:id }).then(res => {
         this.$loadingclose();
        if (res.code == 200) {
       this.$toast('抢单成功')
       this.tableData[index].owntag=1;
        } 
        else{
          this.$toast(res.message)
        }
      },err=>{
             this.$loadingclose();
      });


    },
      reset()
    {
    this.page=1;
    this.total=0;
    this.searchtag=0;
    
    this.getpossiblemembers(1);



    },
    gosearch()
    {
    this.page=1;
    this.total=0;
    this.searchtag=1;
    this.getpossiblemembers(0);



    },
    getpossiblemembers(tag){

    this.$loadingshow();
       getpossiblemembers({refreshtag:tag, page:this.page,searchtag:this.searchtag,size:20,customertype:this.radio,key:this.select,keyword:this.input5,key2:this.value }).then(res => {
       this.$loadingclose();
       if (res.code == 200) {
              this.tip=true;
              this.tableData=res.result.list;
              if(this.searchtag==0)
              {
                localStorage.setItem('possiablemembers',JSON.stringify(this.tableData))
                this.available=71-res.message;
                if(this.available<=0)
                {
                     this.$toast('刷新次数已达71次，明天再来刷新')
                }

              }
              this.total=res.result.total;
              for(var i=0;i<this.tableData.length;i++)
              {
                   this.tableData[i].index=i;
                   this.tableData[i].typedesc=this.tableData[i].type==1?'重点':'普通'


              }
              //document.getElementsByClassName('el-table__body-wrapper')[0].style.height='auto';
        } 
        else{
          console.log('error')
          /*if(localStorage.getItem('possiablemembers') )
          {
          var cache= localStorage.getItem('possiablemembers');
 
          this.tableData=JSON.parse(cache);

              for(var i=0;i<this.tableData.length;i++)
              {
                 this.tableData[i].index=i;
                 this.tableData[i].typedesc=this.tableData[i].type==1?'重点':'普通'


              }


          }*/

          this.$toast(res.message)
        }
      });
    },
    
    filterTag(value,row){
return value===row.owntag;
    },
handleSizeChange(){
 console.log('size change')
},
handleCurrentChange(){
   this.getpossiblemembers(0);
  
},
handleClick(row) {

   this.$confirm('确认关闭？')
          .then(_ => {
        console.log(row);
        row.updatetag=2;
          })
          .catch(_ => {});

      },
      handleClick2(row) {
        console.log(row);
        row.updatetag=1;
        console.log("row的新值:"+row.updatetag)
      },
         addmember(){
                  console.log('username:'+this.additem.username)

  var reg = /^[\u4E00-\u9FA5\uf900-\ufa2da-zA-z•s]{2,20}$/;    
        if(!this.additem.username||(this.additem.username+'').match(reg)==null)
        {
           this.$toast('姓名有误')
           return;
        }
        this.additem.creditcard=this.additem.creditcard.replace(/\r\n/g,"")
         this.additem.creditcard=this.additem.creditcard.replace(/\s/g,"")
 if(!this.IdentityCodeValid(this.additem.creditcard))
        {
           this.$toast('身份证号有误，请检查')
           return;
        }
        if(!this.isPoneAvailable(this.additem.phone))
        {
          this.$toast('手机号有误')
           return;
        }
      this.additem.age=this.GetAge(this.additem.creditcard)

     this.additem.comment=0;
        for(var i=0;i<this.prices.length;i++)
        {
            if(this.additem.age<=this.prices[i].agemax&&this.additem.age>=this.prices[i].agemin)
            this.additem.comment=this.prices[i].price;

        }
         



          this.additem.ids=this.idindex;
          this.additem.orderid=this.$route.query.id;
          

          this.additem.relation=1;
          this.additem.children=[];
          //  this.additem.hasChildren=true;
          console.log('id:'+this.idindex)

          // console.log(JSON.stringify(this.member[0]))
          // console.log(JSON.stringify(this.additem))
          //   this.member.push(this.additem)
                //  var temp=this.member;
                //  temp.push(this.additem)
             this.member.push(this.additem)
         //   this.member.push(this.additem)
        //  this.$set(this.member,  this.member.length,  this.additem)
        // this.member=[];
        // this.tabletag=false;

        // this.$nextTick(function(){
          // console.log('refresh')
          // this.member=temp;
          // this.tabletag=true;


        // })
        // 
              // this.$set(this.member[this.member.length-1], 'hasChildren', true)

            // this.member=temp;
            this.additem={relation:1};
            this.idindex+=1;
            this.popvisiable=false;
            // this.$nextTick(function(){

            //   this.$forceUpdate();

            // })
            // console.log(JSON.stringify(this.member))
            // console.log(this.member)

          
      },
         getpricelist(){
    
          getpricelist(this.itemids).then(res => {
      this.$loadingclose();
       if (res.code == 200) {
         if(res.result.length>0)
              this.prices=res.result[0].data;
        } 
        else{
          this.$toast(res.message)
        }
      });
         


      },
      addhomemember(){
         var reg = /^[\u4E00-\u9FA5\uf900-\ufa2da-zA-z•s]{2,20}$/;    
         console.log('username:'+this.addhome.username)
        if(!this.addhome.username||(this.addhome.username+'').match(reg)==null)
        {
          this.$toast('姓名有误')
           return;
        }
    this.addhome.creditcard=this.addhome.creditcard.replace(/\r\n/g,"")
         this.addhome.creditcard=this.addhome.creditcard.replace(/\s/g,"")
 if(!this.IdentityCodeValid(this.addhome.creditcard))
        {
            this.$toast('身份证号有误，请检查')
           return;
        }
        if(this.addhome.relation!=3&&!this.isPoneAvailable(this.addhome.phone))
        {
          this.$toast('手机号有误')
           return;
        }
        this.addhome.age=this.GetAge(this.addhome.creditcard)
this.addhome.comment=0;
        for(var i=0;i<this.prices.length;i++)
        {
            if(this.addhome.age<=this.prices[i].agemax&&this.addhome.age>=this.prices[i].agemin)
            this.addhome.comment=this.prices[i].price;

        }
         var index=this.currentindex;
          this.addhome.ids=this.idindex;
          this.addhome.son=true;
          this.addhome.children=[];
         this.addhome.orderid=this.$route.query.id;

          var currentindex=0;
  for (var p in this.member) {//遍历json数组时，这么写p为索引，0,1
   var children= this.member[p].children;
   if(currentindex==index)
   {
     console.log('row num:'+p)
    // mem.splice(p,1)
    if(children)
    children.push(this.addhome)
    else
    {
      var childrenc=[];
              childrenc.push(this.addhome)
              // console.log(childrenc)
           this.member[p].children=childrenc;
            // console.log(this.member)
    }
     this.idindex+=1;
     this.addhome={relation:2};
    
 
           var temp=this.member;
           this.member=[];
         
           this.$nextTick(function(){
             

          this.member=temp;  
      //   let treeData=this.$refs.treeTable.store.states.treeData;
      //     console.log(treeData)
      //    if (typeof (treeData[1])== "undefined") {
      //         console.log('未定义'+treeData[1])
      //   return
      // }
      //  console.log('展开了：'+treeData[this.member[p].ids].expanded)
      // if (!treeData[this.member[p].ids].expanded){
      //   console.log('展开')
      //   this.$refs.treeTable.toggleRowExpansion(treeData[this.member[p].ids])
      // }
 
      
       

        })
            

            this.dialogVisible=false;
            // this.$nextTick(function(){
            //   this.$forceUpdate();

            // })
            
     return;
   }
   currentindex+=1;
    if(children)
   {
    for (var q in children) { 
      if(currentindex==index)
   {
    console.log('child row num:'+q)
    if(children[q].children)
    children[q].children.push(this.addhome)
    else
    {
      var childrenc=[];
              childrenc.push(this.addhome)
             children[q].children=childrenc;
    }
   //  children.splice(q,1)
   this.idindex+=1;
            this.dialogVisible=false;
            this.addhome={};
          // this.$forceUpdate();
     return;
   }
     currentindex+=1;

    }
   } 
 
}

           

},
editmember(){
       if(this.edititem.relation!=3&&!this.isPoneAvailable(this.edititem.phone))
        {
        this.$toast('手机号有误')
           return;
        }
  if(!this.IdentityCodeValid(this.edititem.creditcard))
        {
          this.$toast('身份证号有误，请检查')
           return;
        }
        this.edititem.age=this.GetAge(this.edititem.creditcard)+"";
        this.edititem.comment=0;
        for(var i=0;i<this.prices.length;i++)
        {
            if(this.edititem.age<=this.prices[i].agemax&&this.edititem.age>=this.prices[i].agemin)
            this.edititem.comment=this.prices[i].price;

        }
        // if(this.edititem.comment==0)
        // {
        //   layer.msg('产品可能未选择，请检查')

        //    return;
        // }
        var reg = /^[\u4E00-\u9FA5\uf900-\ufa2da-zA-z•s]{2,20}$/;   
        console.log("新名字："+this.edititem.username) 
        if(!this.edititem.username||(this.edititem.username+'').match(reg)==null)
        {
          this.$toast('姓名有误')
           return;
        }
        // var dt=this.edititem;
        // this.edititempointer=dt;
        this.updatemember();
  this.dialogeditVisible = false


},
updatemember(){
  var index=this.currentindex;
  var currentindex=0;
  for (var p in this.member) {//遍历json数组时，这么写p为索引，0,1
   var children= this.member[p].children;
   if(currentindex==index)
   {
     console.log('row num:'+p)
    //  this.member[p]=this.edititem;
    this.member[p].username=this.edititem.username;
    this.member[p].creditcard=this.edititem.creditcard;
    this.member[p].son=this.edititem.son;
    this.member[p].age=this.edititem.age;
    this.member[p].relation=this.edititem.relation;
    this.member[p].comment=this.edititem.comment;
    this.member[p].phone=this.edititem.phone;
     return;
   }
   currentindex+=1;
   if(children)
   {
    for (var q in children) { 
      console.log('index:'+index)
      if(currentindex==index)
   {
    console.log('child row num:'+q)
    console.log('row num:'+p)

    this.member[p].children[q].username=this.edititem.username;
    this.member[p].children[q].creditcard=this.edititem.creditcard;
    this.member[p].children[q].son=this.edititem.son;
    this.member[p].children[q].age=this.edititem.age+"";
    this.member[p].children[q].relation=this.edititem.relation;
    this.member[p].children[q].comment=this.edititem.comment;
    this.member[p].children[q].phone=this.edititem.phone;

    // this.$forceUpdate();
    console.log('update')
    var temp=this.member;
           this.member=[];
          //  this.tabletag=false;
          // this.member.push(this.)
           this.$nextTick(function(){
            // console.log('refresh2')

          this.member=temp;
          // console.log(JSON.stringify(this.member) );
      
          // this.tabletag=true;

        })

     return;
   }
     currentindex+=1;

    }
   }
 
}

},
delmember(index,mem2){
  this.$confirm('确认删除？')
          .then(_ => {
           this.delmemberok(index,mem2);
          })
          .catch(_ => {});

},
delmemberok(index,mem2){
  var currentindex=0;
  for (var p in this.member) {//遍历json数组时，这么写p为索引，0,1
   var children= this.member[p].children;
   if(currentindex==index)
   {
     console.log('row num:'+p)
     this.member.splice(p,1)
     return;
   }
   currentindex+=1;
   if(children)
   {
    for (var q in children) { 
      console.log('index:'+index)
      if(currentindex==index)
   {
    console.log('child row num:'+q)
    console.log('row num:'+p)

    this.member[p].children.splice(q,1)
    // this.$forceUpdate();
    console.log('update')
    var temp=this.member;
           this.member=[];
          //  this.tabletag=false;
          // this.member.push(this.)
           this.$nextTick(function(){
            // console.log('refresh2')

          this.member=temp;
          // console.log(JSON.stringify(this.member) );
      
          // this.tabletag=true;

        })

     return;
   }
     currentindex+=1;

    }
   }
 
}

},
  tijiao(tag)
            {


this.$loadingshow();
       updatememberofpolicy(this.member).then(res => {
      this.$loadingclose();
       if (res.code == 200) {
            this.$store.dispatch('tagsView/delCachedView', {name:'customerlead'})
          //只更新保单状态
             this.$toast('更新成功，请到保单列表进行支付该保单')
               
           //   document.getElementsByClassName('el-table__body-wrapper')[0].style.height='auto';
        } 
        else{
          this.$toast(res.message)
        }
      });






        
            
            }
  }
}
</script>

<style lang="scss" scoped>
.buttonarea{
  width:90%;
  // height: 50px;
}
.btn{
  position: relative;
    /* left: 73%; */
    float: right;
    right: 9px;
    margin-top: 6px;
}
.block{
      text-align: center;
      margin-top:10px;
}

.documentation-container {
  // margin: 50px;
  .document-btn {
    float: left;
    margin-left: 50px;
    display: block;
    cursor: pointer;
    background: black;
    color: white;
    height: 60px;
    width: 200px;
    line-height: 60px;
    font-size: 20px;
    text-align: center;
  }
}
   .popstyle{
        width: 100%;
        height: 30%;
    }
    .userfile{
    width: 90px;
    height: 30px;
    background: cornflowerblue;
    font-size: 14px;
    color: #fff;
    line-height: 30px;
    border-radius: 10px;
    text-align: center;
    margin: 0 auto;
    margin-top: 20px;
}

</style>
